//
//  ViewController.m
//  Category
//
//  Created by Burn on 2020/1/6.
//  Copyright © 2020 menksoft. All rights reserved.
//

#import "ViewController.h"
#import <MJRefresh.h>
#import "MKRefreshHeaderView.h"
#import "UIScrollView+Refresh.h"
#import "TestCell.h"
#import "BViewController.h"
#import "CViewController.h"
#import "TestHeader.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadInterface)];
//    header.lastUpdatedTimeLabel.hidden = YES;
//    self.tableView.mj_header = header;
    
    self.view.backgroundColor = [UIColor redColor];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([TestCell class]) bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TestID"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.backgroundColor = [UIColor yellowColor];
    
    
    
    self.tableView.mk_header = [MKRefreshHeaderView headerWithRefreshingTarget:self refreshingAction:@selector(loadInterface)];
    self.tableView.mk_footer = [MKRefreshFooterView footerWithRefreshingTarget:self refreshingAction:@selector(loadmoreDate)];
    
    
    TestHeader *headerView  = [[TestHeader alloc]initWithFrame:CGRectMake(0, 0, 414, 70)];
    headerView.backgroundColor = [UIColor purpleColor];
    
    self.tableView.mk_header.customHeader = headerView;
    
    /*
    UIView *tableHeader = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 414, 100)];
    tableHeader.backgroundColor = [UIColor redColor];
    self.tableView.tableHeaderView = tableHeader;
     */
    


}

- (void)loadInterface{
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [self.tableView.mk_header endRefreshing];
//    });
}

- (void)loadmoreDate{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.tableView.mk_footer endRefreshing];
    });
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 15;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [self.tableView.mk_header endRefreshing];
    //    CViewController *vc = [[CViewController alloc]init];
    //    [self.navigationController pushViewController:vc animated:YES];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 414, 50)];
    sectionView.backgroundColor = [UIColor cyanColor];
    return sectionView;
}



- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *sectionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 414, 50)];
    sectionView.backgroundColor = [UIColor cyanColor];
    return sectionView;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 101;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TestID"];
    if (!cell) {
        cell = [[TestCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TestID"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"%ld---%ld",indexPath.section,indexPath.row];
    return cell;
}



@end
